<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03-计算属性的setter和getter.html</title>
</head>

<body>
  <div id='app' v-cloak>
    <h2>{{fullNmae}}</h2>

  </div>
  <script src='../js/vue.js'></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello Vue',
        firsName: 'a',
        lastName: 'b'
      },
      computed: {
        // fullNmae: function() {
        //   return this.firsName + ' ' + this.lastName
        // },
        //计算属性一般没有set,只读属性
        fullNmae: {
          set: function(newValue) {
            console.log(newValue, '----');
            let names = newValue.split(' ');
            this.firsName = names[0]
            this.lastName = names[1]
          },
          get: function() {
            return this.firsName + ' ' + this.lastName
          }
        }
      }
    })
  </script>
  <style>
    [v-cloak] {
      display: none;
    }
  </style>
</body>

</html>